#ifndef _GENTITY_H_   
	#define _GENTITY_H_ 

#include <vector>

#include "GAnimation.h"
#include "SDLSurface.h"
#include "GArea.h"
#include "GCamera.h"
#include "GFPS.h"

/*
Extend the Entity class: 
things like this include the ability to Move an Entity, 
Collision (what we've all been waiting for), 
Animation states, and Entity Flags.
*/
enum 
{
	ENTITY_TYPE_GENERIC = 0,

	ENTITY_TYPE_PLAYER
};

enum
{
	ENTITY_FLAG_NONE = 0,

	//An entity that is affected by gravity flag
	ENTITY_FLAG_GRAVITY = 0x00000001,
	//An Entity that can go through walls flag
	ENTITY_FLAG_GHOST = 0x00000002,
	//An entity that only collides with the map flag
	ENTITY_FLAG_MAPONLY = 0x00000004
};

class GEntity
{
public: 
	static std::vector<GEntity*> EntityList;

public:
	static GEntity EntityControl;

protected:
	GAnimation Anim_Control;

	SDL_Surface* Surf_Entity;

public:
	float	X;
	float	Y;

	int		Width;
	int		Height;

	bool	MoveLeft;
	bool	MoveRight;
	bool	MoveUp;
	bool	MoveDown;

public:
	int		Type;

	bool	Dead;
	int		Flags;

	int		AnimState;

protected:
    float   SpeedX;
    float   SpeedY;

    float   AccelX;
    float   AccelY;

public:
    float   MaxSpeedX;
    float   MaxSpeedY;

protected:
	//These two determine where on our image we start to find individual frames of an animation
    int     CurrentFrameCol;
    int     CurrentFrameRow;

protected:
    int     Col_X;
    int     Col_Y;
    int     Col_Width;
    int     Col_Height;
	
public:
	GEntity();
	virtual ~GEntity();

	//we have basic information about the Entity, 
	//common to all Entities, coordinates, dimensions, and a surface for its image
public:
	virtual bool OnLoad(char* File, int Width, int Height, int MaxFrames);

	virtual void OnLoop();

	virtual void OnRender(SDL_Surface* Surf_Display);

	virtual void OnCleanup();

	//OnAnimate is used to define Animation States
	//This is useful for selecting the right direct animation
	virtual void OnAnimate();

	//OnCollision, is called when an Entity collides with another Entity
    virtual bool OnCollision(GEntity* Entity);

public:
	//Make player move
    void OnMove(float MoveX, float MoveY);

    void StopMove();

public:
    bool Collides(int oX, int oY, int oW, int oH);

public:
	void EdgeDetection();

public:
	//The main function that handles the other two
    bool PosValid(int NewX, int NewY);

	//Entity collides with the map
    bool PosValidTile(GTile* Tile);

	////Entity collides with entity
    bool PosValidEntity(GEntity* Entity, int NewX, int NewY);        
};

#endif